package com.ljx.thread.thread02;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2022/10/31 14:59
 * @Version 1.0
 */
public class TicketThread implements Runnable{
	private Object object=new Object();
	/**
	 定义票数
 	 */
	private int ticket=100;


	@Override
	public void run() {
		while (true){
			synchronized (object){
			if (ticket>0){

				// 如果票数大于0 就继续买票否则就结束买票
				System.out.println(Thread.currentThread().getName()+"卖出一张票剩余"+--ticket);
			} else {
				System.out.println(Thread.currentThread().getName()+"没票了，sorry");
				break;
			}
			}
		}

	}
}
